package com.chuanke.ckfamily.service.finance.impl;
import com.chuanke.ckfamily.service.common.TipsService;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.chuanke.ckfamily.dao.finance.RedPacketRuleDao;
import com.chuanke.ckfamily.dao.finance.model.RedPacketRule;
import com.chuanke.ckfamily.service.base.FailCode;
import com.chuanke.ckfamily.service.exception.CFException;
import com.chuanke.ckfamily.service.finance.RedPacketRuleService;
import com.weijie.core.BaseBiz;

import java.io.IOException;

@Service
@Transactional(rollbackFor=Exception.class)
public class RedPacketRuleServiceImpl extends BaseBiz<RedPacketRule, RedPacketRuleDao> implements RedPacketRuleService{

	@Autowired
	private TipsService tipsService;

	@Override
	public RedPacketRule getRedPacketRule(Long money) throws CFException, IOException, TemplateException {
		if(money == null || money <= 0){
			throw new CFException(FailCode.PARAMS_ERROR, tipsService.getSendRedpackage(money));
		}

		return baseDao.getRedPacketRuleByMoney(money / 100);
	}
}